pp108 : Sample Java Code Snippets

Sample Java Code Snippets

This topic provides sample Java code snippets for ApplicationConnector and ApplicationTransaction classes.

ApplicationConnector Class

package com.cordys.countconnector;

import com.eibus.soap.ApplicationConnector;
import com.eibus.soap.ApplicationTransaction;
import com.eibus.soap.Processor;
import com.eibus.soap.SOAPTransaction;


public class CountConnector extends ApplicationConnector {
    // This method gets executed when a service container is started
    public void open(Processor processor) {
        // Check processor configuration, validate it and throw back exceptions
        // if any
    }

    // This method gets executed when a service container is reset
    public void reset(Processor processor) {
        // Any reset operations like cache reset, variables reset etc
    }

    // This method gets executed when a service container is requested to
    // process a soap request
    public ApplicationTransaction createTransaction(
        SOAPTransaction soapTransaction) {
        // Returns the transaction class that processes the soap requests sent
        // to this service container
        return new CountTransaction();
    }
}

ApplicationTransaction Class

package com.cordys.countconnector;

import com.eibus.soap.ApplicationTransaction;
import com.eibus.soap.BodyBlock;

import com.eibus.xml.nom.Node;


public class CountTransaction implements ApplicationTransaction {
    static int count = 1;

    public CountTransaction() {
        // Count transaction constructor
    }

    // This function informs whether a request can be processed or not. The
    // implementation type of the webservcie operation is checked against the
    // list of types that can be processed by this connector.
    public boolean canProcess(String type) {
        return "Count".equals(type);
    }

    // Actual processing happens here
    public boolean process(BodyBlock request, BodyBlock response) {
        int responseNode = response.getXMLNode();
        // Creating status tag in response which is returned as the response to the user
        Node.getDocument(responseNode)
            .createTextElement("status", "This is Method No " + count++,
            responseNode);

        return true;
    }

    //Code that Commits the transaction must come here
    public void commit() {
    }

    //Code that aborts the transaction must come here
    public void abort() {
    }
}